import { _decorator, dragonBones, JsonAsset } from 'cc';
import { app } from 'db://app-game/core/app';
import AnimatorDragonBones from 'db://app-game/libs/animator/AnimatorDragonBones';
import { AnimatorStateLogic } from 'db://app-game/libs/animator/core/AnimatorStateLogic';
import { Role } from '../Role';
import { AnimationEventHandler } from './animator/AnimationEventHandler';
import { RoleLowerBodyAnimatorParamsEnum } from '../Role.type';

const { ccclass, requireComponent, disallowMultiple } = _decorator;

/** 角色上半身动画规则管理 */
@ccclass('RoleViewLowerBodyAnimator')
@disallowMultiple
@requireComponent(dragonBones.ArmatureDisplay)
export class RoleViewLowerBodyAnimator extends AnimatorDragonBones {
  /** 角色对象 */
  role: Role = null!;

  protected async start() {
    // 1.获取状态机
    await this.animatorGraph();

    // 2.初始化状态机
    super.start();

    // 3.动画状态机
    let anim = new AnimationEventHandler();
    let asl: Map<string, AnimatorStateLogic> = new Map();

    this.initArgs(asl, anim);
  }

  /** 初始化状态机参数 */
  async animatorGraph() {
    const animatorGraphPath = this.role.RoleModelJob.roleDragonBones.lowerBody.animatorGraphPath;
    const config = await app.res.loadAsync(animatorGraphPath, JsonAsset);
    this.AssetRawUrl = config;
  }

  // /**
  //  * 播放动画
  //  * @override
  //  * @param animName 动画名
  //  * @param loop 是否循环播放
  //  */
  // protected playAnimation(animName: string, loop: boolean) {}
}
